<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<html>
<head>
<title>${title }</title>
<link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css" />
<link rel="stylesheet" href="${ctx }/static/styles/frame/main.css" />
<link rel="stylesheet" href="${ctx }/static/styles/frame/searchBtn.css" />
<link rel="stylesheet" href="${ctx }/static/styles/frame/searchCondition.css" />
<!-- js -->
<script type="text/javascript" src="${ctx}/static/scripts/check_all.js"></script>
<script type="text/javascript" src="${ctx}/static/scripts/set_select.js"></script>
<script type="text/javascript" src="${ctx}/static/scripts/waiting.js"></script>
<script type="text/javascript" src="${ctx}/static/scripts/crud.js"></script>
<script type="text/javascript" src="${ctx}/static/scripts/util.js"></script>
<script type="text/javascript" src="${ctx}/static/scripts/WdatePicker/WdatePicker.js"></script>
</head>
<body onload="init()">
	<form action="${ctx}/customer/list" method="post">
		<input type="hidden" name="RequestVerificationToken" value="${RequestVerificationToken}" />
		<div class="width_100 group_box">
			<div class="group_search width_100">
				<vvise:searchInput id="custCode" name="p_custCode"
					displayText="客户编码" />
				<vvise:searchInput id="custName" name="p_custName"
					displayText="客户名称" />
				<vvise:searchInput id="startDate" name="p_startDate"
					endId="endtDate" endName="p_endDate" type="time2"
					displayText="录入日期" dateFormat="yyyy-MM-dd" />
				<div class="clear_both"></div>
			</div>
			<vvise:funMenu menuId="${menuId}" />
		</div>
	</form>
	<div class="listFrame">
		<iframe name="listFrame" id="listFrame" frameBorder="0"
			scrolling="auto" style="width: 100%; height: 100%;"></iframe>
	</div>
</body>
<script type="text/javascript">
	var headers = {};
	headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
	//回车事件
	document.onkeydown = keyKistener;
	function keyKistener(e) {
		e = e ? e : event;
		if (e.keyCode == 13) {
			try {
				search();
			} catch (e) {
			}
		}
	}
	function init() {
		set_iframe_h();
		$(window).resize(function() {
			set_iframe_h();
		});
		search();
		$('.easyui-combobox').combobox();
	}
	//设置ifream 高度
	function set_iframe_h() {
		var win_height = $(window).height();
		var func_line_h = $('.group_box').outerHeight(true);
		var list_height = win_height - func_line_h;
		$('.listFrame').css('height', list_height - 10);
	}
	function search() {
		waiting();
		document.forms[0].target = "listFrame";
		document.forms[0].submit();
	}

	function create(custId) {
		if (parent.isEmpty(custId))
			custId = "";

		var pp = parent;
		doCreate("客户信息", pp.width2, 280, "${ctx}/customer/edit?custId="
				+ custId);
	}

	function save() {
		var pp = parent;
		var editFrame = pp.winFrame;
		var custId = editFrame.$('#custId').val();
		var custCode = editFrame.$('#custCode').val();
		var custName = editFrame.$('#custName').val();

		if (!pp.validData("custCode", "请输入客户编码！"))
			return false;

		if (!pp.validData("custName", "请输入客户名称！"))
			return false;

		var flag = executeAjaxBySync('${ctx}/customer/checkName', 'custCode=' + custCode + "&custId=" + custId);
		if (flag == 'error') {
			pp.$.messager.alert('操作提示', '该客户编码已经存在，请重新输入', 'warning',
				function() {
					editFrame.$('#custCode').focus();
				});
			return false;
		}
		
		var flag = executeAjaxBySync('${ctx}/customer/checkName', 'custName=' + custName + "&custId=" + custId);
		if (flag == 'error') {
			pp.$.messager.alert('操作提示', '该客户名称已经存在，请重新输入', 'warning',
				function() {
					editFrame.$('#custName').focus();
				});
			return false;
		}
		doSave("${ctx}/customer/save", custId);
	}

	function view(custId) {
		var pp = parent;
		doView("客户信息", pp.width2, 280, "${ctx}/customer/edit?custId=" + custId
				+ "&view=view");
	}

	function removeF() {
		var pp = parent;
		var ids = "";
		var ecForm = listFrame.document.all.ec;
		if (!checkSelect(ecForm.id, true))
			return;
		ids = get_checkbox_values(ecForm.id, ',');

		pp.confirmMsg("确定要删除吗？", function() {
			var urls = "${ctx}/customer/delete";
			var params = "custIds=" + ids;
			executeAjax(urls, params, function(data) {
				if (data != 'error') {
					pp.$.messager.alert('操作提示', "操作成功！", "info", function() {
						listRefresh();
					});
				} else {
					pp.$.messager.alert('操作提示', "操作失败！", "error");
				}
			});
		});
	}
</script>
</html>